var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "licenseNo",
			name : "车牌号"
		}, {
			colkey : "carBossName",
			name : "车老板姓名"
		}, {
			 colkey : "transpor",
				name : "司机",
				renderData : function(rowindex,data, rowdata, column) {
					var driverName="";
					$.each(data,function(i,v){
						driverName = v.driverName;
						return driverName;
					});
					return driverName;
				}
		},{
			colkey : "carBossNumber",
			name : "车老板联系电话"
		},{
			colkey : "transpor",
			name : "司机联系电话",
			renderData : function(rowindex,data, rowdata, column) {
				var driverNumber="";
				$.each(data,function(i,v){
					driverNumber = v.driverNumber;
					return driverNumber;
				});
				return driverNumber;
			}
		},{
			colkey : "userName",
			name : "加油负责人"
		},{
			colkey : "refuelNow",
			name : "本次加油公里数"
		},{
			colkey : "cheakId",
			name : "加油量(升)"
		},{
			colkey : "kilometreNumber",
			name : "上次加油公里数"
		},{
			colkey : "totals",
			name : "行驶公里数"
		}],
		jsonUrl : rootPath + '/transportrefuel/transportrefuel_findbyPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#editnewOrder").click("click", function() {
		editAccount();
	});
	$("#editFun").click("click", function() {
		editAccount();
	});
	$("#addFun").click("click", function() {
		addAccount();
	});
	$("#delFun").click("click", function() {
		delAccount();
	});
	
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
	function editAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox.length > 1 ) {
			layer.msg("只能选中一个");
			return;
		}
		if(cbox == ""){
			layer.msg("需要选择一个");
			return;
		}
		pageii = layer.open({
			title : "编辑",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transportrefuel/transportrefuel_edit.shtml?id=' + cbox
		});
	}
	/*function addAccount() {
		pageii = layer.open({
			title : "添加",
			type : 2,
			area : [ "800px", "100%" ],
			content : rootPath + '/transportrefuel/transport_add.shtml'
			});
	}*/
	
	function delAccount() {
		var cbox = grid.getSelectedCheckbox();
		if (cbox == "") {
			layer.msg("请选择删除项！！");
			return;
		}
		layer.confirm('是否删除？', function(index) {
			var url = rootPath + '/transportrefuel/transportrefuel_deleteEntity.shtml';
			var s = CommnUtil.ajax(url, {
				ids : cbox.join(",")
			}, "json");
			if (s == "success") {
				layer.msg('删除成功');
				grid.loadData();
			} else {
				layer.msg('删除失败');
			}
		});
	}
});
